﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RechercheEmplois.Models;

namespace RechercheEmplois.Utilities
{
    public class OffreComparator : IComparer<Offre>
    {
        string searchKeys;
        string[] selectedProvines;
        string[] selectedTypes;
        string[] selectedSecteurs;
        string[] selectedNiveauEtudes;
        int remuValue = 0;
        private int? remuValue1;
        private double TOLERANCE = 0.0001d;

        public OffreComparator(string searchKeys, string[] selectedProvines, string[] selectedTypes, string[] selectedSecteurs, string[] selectedNiveauEtudes, int? remuValue)
        {
            this.searchKeys = searchKeys;
            this.selectedProvines = selectedProvines;
            this.selectedTypes = selectedTypes;
            this.selectedSecteurs = selectedSecteurs;
            this.selectedNiveauEtudes = selectedNiveauEtudes;
            if (remuValue != null)
                this.remuValue = (int)remuValue;
        }

        //Override
        public int Compare(Offre o1, Offre o2)
        {
            double pro1 = o1.Probabilite(searchKeys, selectedProvines, selectedTypes, selectedSecteurs, selectedNiveauEtudes, remuValue);
            double pro2 = o2.Probabilite(searchKeys, selectedProvines, selectedTypes, selectedSecteurs, selectedNiveauEtudes, remuValue);
            //System.Diagnostics.Debug.WriteLine(o1.Libelle + ": " + pro1 + " vs " + o2.Libelle + ": " + pro2);
            return Math.Abs(pro1 - pro2) < TOLERANCE ? 0 : (pro1 > pro2 ? -1 : 1);
        }
    }
}